CC = gcc
AR = ar
CFLAGS = -Wall -D_REENTRANT -I../libcc -I../libami/include/ -I../fax_sn
LDFLAGS = ../libcc/libcc.a -L/usr/lib/mysql -lmysqlclient ../libami/libami.a ../fax_sn/libsn_pub.a -lpthread -O3 -lcrypto
#

quiet=quiet_
Q = @

quiet_cmd_clean ?= ($(foreach f, $(rm-files), echo "   CLEAN ${f}"; ))
      cmd_clean ?= rm -f ${rm-files}
quiet_cmd_cc ?= echo "   CC $@"
      cmd_cc ?= $(CC) -c -o $@ $(CFLAGS) $<
quiet_cmd_ld ?= echo  "   LD $@"
      cmd_ld ?= $(CC) -o $@ $^ $(LDFLAGS)
quiet_cmd_cppld ?= echo "   LD $@"
      cmd_cppld ?= $(CPP) -o $@ $^ $(TDBFLAGS) $(LDFLAGS)
quiet_cmd_strip ?= echo "   STRIP $@"
      cmd_strip ?= strip $@

cmd = @$(if $($(quiet)cmd_$(1)),$($(quiet)cmd_$(1)) &&) $(cmd_$(1))

#

all: luccd

*.o: *.h Makefile ../libami/libami.a ../libcc/libcc.a

.c.o: 
	$(call cmd,cc)

luccd: main.o log.o db.o thr.o msg.o ast.o \
	db_user.o db_extension.o db_trunk.o db_setting.o db_blacklist.o \
	db_fax.o \
	ch.o call.o channel.o vchan.o fax.o \
	dyn.o mon.o \
	watchdog.o regcode.o
	$(call cmd,ld)
	$(call cmd,strip)

install:
	@mkdir -p /var/log/lucc/
	@mkdir -p /lucc/
	@cp lucc /lucc/
	@cp luccd /lucc/

rm-files = *.o luccd
clean:
	$(call cmd,clean)
